package com.carleasoft.mps.forum.business.answer.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.forum.business.answer.bean.ForumComment;
import com.carleasoft.mps.forum.business.answer.bean.po.ForumUserPo;
import com.carleasoft.mps.forum.business.answer.service.ForumCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zang
 * @since 2023-05-09
 */
@RestController
@RequestMapping("/forumComment")
public class ForumCommentController {
    @Autowired
    private ForumCommentService forumCommentService;

    
    /**
     * @author zang
     * @desc 查询评论
     * @date 2023-05-19
     */
    @PostMapping("/selForumComment")
    public R selForumComment(@RequestBody ForumComment forumComment) {
        List<ForumComment> res = forumCommentService.selForumComment(forumComment);
        return R.ok(res);
    }
    
    /**
     * @author zang
     * @desc 新增评论
     * @date 2023-05-19
     */
    @PostMapping("/saveForumComment")
    public R saveForumComment(@RequestBody ForumComment forumComment) {
        String s = forumCommentService.saveForumComment(forumComment);
        if(s.equals("提交成功")) {
            return R.ok();
        } else {
            return R.failed("000001",s);
        }
    }

    /**
     * @author zang
     * @desc 分页查询
     * @date 2023-06-19
     */
    @PostMapping("/pageForumComment")
    public R pageForumComment(@RequestBody ForumUserPo forumUserPo) {
        Page page = new Page(forumUserPo.getCurrent(), forumUserPo.getSize());
        Page<ForumComment> res = forumCommentService.pageForumComment(page,forumUserPo);
        return R.ok(res);
    }

}

